import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */



export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  

    {
    path: '/information',
    component: Layout,
    redirect: '/information/table',
    name: 'Example',
    meta: { title: '故障信息中心', icon: 'el-icon-document' },
    children: [
      {
        path: 'import',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: { title: '故障信息收集', icon: 'el-icon-edit-outline' },
        show: true
      },
      {
        path: 'list',
        name: 'Tree',
        component: () => import('@/views/tree/index'),
        meta: { title: '故障信息维护', icon: 'el-icon-edit' },
        show: true
      }
    ]
  },

  {
    path: '/datashow',
    component: Layout,
    redirect: '/datashow/table',
    name: 'datashow',
    meta: { title: '故障数据统计', icon: 'el-icon-data-line' },
    children: [
      {
        path: 'machinedata',
        name: 'machinedata',
        component: () => import('@/views/datashow/machine'),
        meta: { title: '机组数据统计', icon: 'el-icon-pie-chart' },
        show: true
      },
      {
        path: 'shortagedata',
        name: 'shortagedata',
        component: () => import('@/views/datashow/information'),
        meta: { title: '缺陷数据统计', icon: 'el-icon-pie-chart' },
        show: true
      }
    ]
  },


  {
    path: '/task',
    component: Layout,
    redirect: '/task/table',
    name: 'Task',
    meta: { title: '设备维修中心', icon: 'el-icon-setting' },
    children: [
      {
        path: 'import',
        name: 'Table',
        component: () => import('@/views/table/mistake'),
        meta: { title: '设备维修信息收集', icon: 'el-icon-edit-outline' },
        show: true
      },
      {
        path: 'list',
        name: 'Tree',
        component: () => import('@/views/tree/mistake'),
        meta: { title: '设备维修信息维护', icon: 'el-icon-tickets' },
        show: true
      }
    ]
  },

  {
    path: '/equipment',
    component: Layout,
    redirect: '/equipment',
    name: '/equipment',
    meta: { title: '设备检测中心', icon: 'el-icon-s-home' },
    children: [{
      path: 'generator',
      name: '电机状态',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '发电机状态评价', icon: 'el-icon-odometer' },
      show: true
    },
    {
      path: '',
      name: '',
      component: () => import('@/views/import/list'),
      meta: { title: '', icon: '' },
      show: false
    },
  ]
  },

  {
    path: '/import',
    component: Layout,
    redirect: '/import',
    name: 'import',
    meta: { title: '工作管理', icon: 'el-icon-s-home' },
    children: [{
      path: 'person',
      name: '工作录入',
      component: () => import('@/views/import/index'),
      meta: { title: '工作录入', icon: 'el-icon-user-solid' }
    },
    {
      path: 'list',
      name: '工作列表',
      component: () => import('@/views/import/list'),
      meta: { title: '工作列表', icon: 'el-icon-user-solid' }
    },
  ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
